package com.eascs.web.o2o.web.reward.controller;

import java.text.DecimalFormat;
import java.text.Format;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.PaginationRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.web.context.RequestContext;
import com.eascs.web.o2o.web.reward.entity.ProvinceSignForm;
import com.eascs.web.o2o.web.reward.service.SignForProvinceService;

@RestController
@RequestMapping(value="/restProvinceSign")
public class SignForProvinceRestController extends BaseRestController{
	
	@Autowired
	SignForProvinceService signForProvinceService;

	/**
	 * 加签率汇总
	 * @param entity
	 * @return
	 */
	@RequestMapping(value="/provinceSignList")
	private PaginationRestResult provinceSignList(ProvinceSignForm entity) {
		String o2oUrl = "/restProvinceSign/provinceSignList";
		if(entity != null) {
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "provinceName", entity.getProvinceName());
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "dateStart", entity.getDateStart());
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "dateEnd", entity.getDateEnd());
			o2oUrl = o2oUrl + "&pageIndex=";
		} else {
			o2oUrl = o2oUrl + "?pageIndex=";
		}
		entity.setPageSize(100);
		PageResult<Object[]> pageResult = signForProvinceService.getProvinceSignList(entity);
		String[] titles = {"省区", "加签次数之和", "经办累计笔数", "加签率", "加签分数"};
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, UrlUtil.resetParam(RequestContext.getRequestUrlWithQueryString(), "pageIndex", ""));
		paginationInfo.setFirstRenderColumnIndex(0);
		paginationInfo.setFormats(new Format[] {null, null, null, new DecimalFormat("##0.00%"), null});
		paginationInfo.setRendTo("#o2o_result");
		ViewContext.put("vo", entity);
		ViewContext.put("o2oUrl", o2oUrl);
		return PaginationRestResult.buildPaginationRestResult(paginationInfo);
	}
	
}
